import Vue from 'vue'
import Router from 'vue-router'
import { Message, MessageBox, Notification } from 'element-ui'
import store from '@/store'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                   // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true               // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect           // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'             // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * meta : {
    noCache: true                // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'               // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'             // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false            // 如果设置为false，则不会在breadcrumb面包屑中显示
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: (resolve) => require(['@/views/redirect'], resolve)
      }
    ]
  },
  {
    path: '/login',
    component: (resolve) => require(['@/views/login'], resolve),
    hidden: true
  },
  {
    path: '/register',
    component: (resolve) => require(['../components/login/registerAccount.vue'], resolve),
    hidden: true
  },
  {
    path: '/404',
    component: (resolve) => require(['@/views/error/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: (resolve) => require(['@/views/error/401'], resolve),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/index'], resolve),
        name: '首页',
        meta: { title: '首页', icon: 'iconfont icon-shouye', noCache: true, affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: (resolve) => require(['@/views/system/user/profile/index'], resolve),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  },
  {
    path: '/dict',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'type/data/:dictId(\\d+)',
        component: (resolve) => require(['@/views/system/dict/data'], resolve),
        name: 'Data',
        meta: { title: '字典数据', icon: '' }
      }
    ]
  },

  {
    path: '/job',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'log',
        component: (resolve) => require(['@/views/monitor/job/log'], resolve),
        name: 'JobLog',
        meta: { title: '调度日志' }
      }
    ]
  },
  {
    path: '/gen',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'edit/:tableId(\\d+)',
        component: (resolve) => require(['@/views/tool/gen/editTable'], resolve),
        name: 'GenEdit',
        meta: { title: '修改生成配置' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/fieldsettings',
        component: (resolve) => require(['@/views/signUp/fieldSettings'], resolve),
        name: 'fieldsettings',
        meta: { activeMenu: '/registerSet/field' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/stafflist',
        component: (resolve) => require(['@/views/RegistrationSettings/staffList'], resolve),
        name: 'stafflist',
        meta: { activeMenu: '/register/onlineregistration' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/personalinfo',
        component: (resolve) => require(['../views/sys/user/personalInfo.vue'], resolve),
        name: 'personalInfo',
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/studentInfo',
        component: (resolve) => require(['../views/IndividualUser/conponments/signUp/studentInfo.vue'], resolve),
        name: 'studentInfo',
        meta: { activeMenu: '/signUp' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/jumppake',
        component: (resolve) => require(['../views/tool/Jumppake.vue'], resolve),
        name: 'jumppake',
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/orderDetails',
        component: (resolve) => require(['../views/IndividualUser/conponments/myOrder/orderDetails.vue'], resolve),
        name: 'orderDetails',
        meta: { activeMenu: '/myOrder' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/modifyOrder',
        component: (resolve) => require(['../views/IndividualUser/conponments/myOrder/modifyOrder.vue'], resolve),
        name: 'modifyOrder',
        meta: { activeMenu: '/myOrder' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/enStudentInfo',
        component: (resolve) => require(['../views/enterprise/conponments/signUp/studentInfo.vue'], resolve),
        name: 'enStudentInfo',
        meta: { activeMenu: '/enSignUp' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/enOrderDetails',
        component: (resolve) => require(['../views/enterprise/conponments/myOrder/orderDetails.vue'], resolve),
        name: 'enOrderDetails',
        meta: { activeMenu: '/enMyOrder' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/enModifyOrder',
        component: (resolve) => require(['../views/enterprise/conponments/myOrder/modifyOrder.vue'], resolve),
        name: 'enModifyOrder',
        meta: { activeMenu: '/enMyOrder' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/task/automation',
        component: (resolve) => require(['../views/task/loopTask/components/automation.vue'], resolve),
        name: 'Automation',
        meta: { activeMenu: '/task/loopTask' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/enInvoiceast',
        component: (resolve) => require(['../views/enterprise/invoiceAst.vue'], resolve),
        name: 'enInvoiceAst',
        meta: { activeMenu: '/enMyOrder' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/detailCustom',
        component: (resolve) => require(['../views/sys/customField/components/detailCustom.vue'], resolve),
        name: 'detailCustom',
        meta: { activeMenu: '/sys/customField' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/calendar',
        component: (resolve) => require(['../components/calendar/index.vue'], resolve),
        name: 'calendar',
        meta: { activeMenu: '/index' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/doCenter',
        component: (resolve) => require(['../components/FwIndex/doCenter.vue'], resolve),
        name: 'docenter',
        meta: { activeMenu: '/index' }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/crm/expContract',
        component: (resolve) => require(['../views/CRM/expContract/index.vue'], resolve),
        name: 'expContract',
        meta: { activeMenu: '/crm/contract' }
      }
    ]
  },
]


const routers = new Router({
  base: '/saas/',
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
routers.beforeEach((to, form, next) => {
  const WhiteList = ['/certificate/certInfo', '/certificate/certUse', '/certificate/certType', '/qualification/qualificationInfo', '/qualification/qualificationCert', '/qualification/qualificationPost', '/qualification/qualificationType', '/qualification/qualificationDeposit', '/certificate/certDeposit']
  let token = store.state.user.token
  if (token) store.dispatch("isVip");
  let isVip = localStorage.getItem('isVip')
  if (WhiteList.indexOf(to.path) != -1 && isVip == 'false') {
    Message({
      message: '会员信息已过期，导致该功能停止使用，请尽快续费',
      type: 'info'
    })
  } else {
    next()
  }
})
export default routers

